package com.example;

import com.example.database.WikiDatabaseVerticle;
import com.example.http.HttpServerVerticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;

public class MainVerticle extends AbstractVerticle {

    @Override
    public void start(Promise<Void> promise) throws Exception {
        Promise<String> dbVerticleDeployment = Promise.promise();

        vertx.deployVerticle(new WikiDatabaseVerticle(),dbVerticleDeployment);

        dbVerticleDeployment.future().compose(id->{
            Promise<String> httpVerticleDeployment = Promise.promise();

            vertx.deployVerticle(HttpServerVerticle.class.getName(),
                    new DeploymentOptions().setInstances(2),
                    httpVerticleDeployment
            );
            return httpVerticleDeployment.future();
        }).onComplete(ar->{
            if (ar.failed()){
                promise.fail(ar.cause());
            }else {
                promise.complete();
            }
        });
    }
}
